﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BUS;
using DTO;
using System.Collections.Generic;

namespace TuyenDungViecLam.User_control_VN
{
    public partial class List_Job_Saved : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LienKetDuLieu();
            }
        }

        private void LienKetDuLieu()
        {
            string str = Session["UserID"].ToString();
            gvdscongviec.DataSource = ChiTietCongViec_BUS.LayCongViecDaLuu(int.Parse(Session["UserID"].ToString()));
            gvdscongviec.DataBind();
        }

        protected void gvdscongviec_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lbtrangthai = (Label)e.Row.FindControl("lbtrangthai");
                LinkButton lbcongviec = (LinkButton)e.Row.FindControl("lbcongviec");
                Label lbthongbao = (Label)e.Row.FindControl("lbthongbao");
                ImageButton NopDon = (ImageButton)e.Row.FindControl("NopDon");
                if (lbtrangthai.Text == "0")
                {
                    lbthongbao.Text = "Công việc đã hết hạn";
                    lbthongbao.ForeColor = System.Drawing.Color.Red;
                    lbcongviec.ForeColor = System.Drawing.Color.Black;
                    lbthongbao.Visible = true;
                    NopDon.Visible = false;
                }
                else
                {
                    lbcongviec.ForeColor = System.Drawing.Color.Blue;
                }
            }
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            for (int i = gvdscongviec.Rows.Count - 1; i >= 0; i--)
            {
                Label lbmacongviec = (Label)gvdscongviec.Rows[i].Cells[0].FindControl("lbmacongviec");
                CheckBox cbchon = (CheckBox)gvdscongviec.Rows[i].Cells[0].FindControl("cbchon");
                if (cbchon.Checked == true)
                {
                    NguoiTimViec_BUS.HuyCongViecDaXem(int.Parse(Session["UserID"].ToString()), int.Parse(lbmacongviec.Text));
                }
            }
            LienKetDuLieu();
        }

        protected void gvdscongviec_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Link")
            {
                string Mct = "";
                string TrangThai = "";
                ChiTietCongViec_BUS.LayMaCongTyTuMaCongViec(e.CommandArgument.ToString(), ref Mct, ref TrangThai);
                string url = "";
                if (TrangThai == "1")
                {
                    url = "../VN/ChiTietCongViec.aspx?Mcv=" + e.CommandArgument.ToString() + "&Mct=" + Mct;
                    Response.Redirect(url);
                }
            }
            if (e.CommandName == "chon")
            {
                for (int i = 0; i < gvdscongviec.Rows.Count; i++)
                {
                    CheckBox cbchon = (CheckBox)gvdscongviec.Rows[i].FindControl("cbchon");
                    cbchon.Checked = true;
                }
            }
            if (e.CommandName == "NopDon")
            {
                string url = "NopCVOnline.aspx?Mct=" + e.CommandArgument.ToString();
                Response.Redirect(url);
            }
        }

        protected void gvdscongviec_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvdscongviec.PageIndex = e.NewPageIndex;
            LienKetDuLieu();
        }

    }
}